<!DOCTYPE html>
<html xmlns:javascrip="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>资源详情明细</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<style>
    /*媒体查询 小于750 的样式*/
    @media screen and (max-width: 999px) {
        .mid{
            width: 100%;
            text-align: center;
            margin-top: 10px;
        }
    }
    @media screen and (min-width: 999px) {
        .layui-table-cell{
            width: calc((100vw *0.7) / 4)!important;
        }

    }
</style>
<body>

<div class="layui-card">
    <div  class="layui-form layui-card-header layuiadmin-card-header-auto">


        <form class="layui-form" action="">
            <input type="hidden" id="fk_resource_id">
            <div class="layui-inline" >
                <label class="layui-form-label">搜索</label>
                <div class="layui-input-inline">
                    <input type="text"  id="content"  autocomplete="off" class="layui-input">
                </div>
            </div>
        </form>
    </div>

    <div class="layui-card-body">
        <div class="layui-inline mid">
            <button class="layui-btn add" >
                新建字段
            </button>
            <button class="layui-btn layuiadmin-btn-order" id="search" lay-submit="" lay-filter="LAY-app-order-search">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
        </div>

        <table id="demo"  lay-filter="xx">
        </table>
    </div>
</div>
    <script type="text/html" id="barDemo">
        {{#  if(d.is_system == 'false'){ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="open"><i class="layui-icon layui-icon-console"></i></a>
        <!--<a class="layui-btn  layui-btn-xs " lay-event="edit">改</a>-->
        <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete">删</a>-->
        {{#  } }}

    </script>


<script src="/js/include.js" type="text/javascript" charset="utf-8"></script>
<script type="text/jscript" src="/js/print.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    var resource_name="resource_detail";
    var QueryParam= new Object();

    var url = window.location.search;
    if (url != null && url != "") {
        url = url.substr(1, url.length);
        if (parseJson(url).id != "") {
            $('#fk_resource_id').val(parseJson(url).id);
            QueryParam.term={fk_resource_id:$('#fk_resource_id').val()};
            //layui 表格
            layui.use('table', function(){
                //表格数据装载
                var table = layui.table;
                table.render({
                    id: 'idTest',
                    url:'/dbm/resource/resources_detail_list/',
                    method:'post',
                    where: {fk_resource_id: $('#fk_resource_id').val()},
                    page:true,
                    limits:[10,20],
                    limit:10,
                    elem: '#demo', //指定原始表格元素选择器（推荐id选择器）
                    height: 515 ,//容器高度
                    cols: [[
                        {field: 'rd_cn_name', title: '中文名称',width:120},
                        {field: 'rd_name', title: '英文名称',width:120},
                        {field: 'rd_length', title: '长度',width:120},
                        {field: 'field_type', title: '类型',width:120},
                        {fixed: 'right', width:'30%',align:'center', toolbar: '#barDemo'}]], //设置表头

                    response:{
                        statusName: 'success', //数据状态的字段名称，默认：code
                        statusCode: true ,//成功的状态码，默认：0
                        msgName: 'message', //状态信息的字段名称，默认：msg
                        countName: 'count', //数据总数的字段名称，默认：count
                        dataName: 'data' //数据列表的字段名称，默认：data
                    }
                    //,…… //更多参数参考右侧目录：基本参数选项
                });
                //监听工具条
                table.on('tool(xx)', function tata(obj){

                    var data = obj.data,layEvent = obj.event;
                    if(layEvent === 'open'){
                        var btns=[];
                        if(data.is_system == 'false'){
                            btns=[
                                '<i class="layui-icon layui-icon-edit"></i>',
                                '<i class="layui-icon layui-icon-delete"></i>'];
                        }else {
                            layer.msg('程序有问题，请联系管理员');
                            return false;
                        }
//配置一个透明的询问框
                        layer.msg('', {
                            time: 3000, //20s后自动关闭
                            offset: 't',
                            content:'<input type="hidden" name="p_id" value="'+data.id+'">',
                            btn: btns,
                            //编辑
                            yes: function(index, layero){
                                var index = layer.open({
                                    type: 2,
                                    content: '/html/resource/resource_detail_from.html?fk_resource_id='+$('#fk_resource_id').val()+'&id='+data.id,
                                    area: ['100%', '100%'],
                                    maxmin: false
                                });
                            },
                            //删除
                            btn2: function(index, layero){
                                layer.confirm('删除字段后无法恢复，继续？', function(index){
                                    $.ajax({
                                        url:"/layui/table/delete",
                                        type:"post",
                                        data:{id:data.id,resource_name:resource_name},
                                        async:false,
                                        success:function (data) {
                                            if(data.success){
                                                layer.msg("删除成功")
                                                obj.del(); //删除对应行（tr）的DOM结构
                                            }else {
                                                layer.msg(data.message)

                                            }
                                        }
                                    })
                                    layer.close(index);
                                    //向服务端发送删除指令
                                });
                            }
                        });
                    }

                });
            });
        }
    }


    function parseJson(param) {
        var obj = {};
        var keyvalue = [];
        var key = "", value = "";
        var paraString = param.split("&");
        for (var i in paraString) {
            keyvalue = paraString[i].split("=");
            key = keyvalue[0];
            value = keyvalue[1];
            obj[key] = value;
        }
        return obj;
    }
    //查询
    $("#search").click(function () {
        query();
    })
    //新增
    $(".add").click(function () {
        save();
    })
    //保存共用方法
    function save (id) {
        id=(id==undefined)?(""):("&id="+id);
        var index = layer.open({
            type: 2,
            content: '/html/resource/resource_detail_from.html?fk_resource_id='+$('#fk_resource_id').val(),
            area: ['100%', '100%'],
            maxmin: false
        });
        layer.full(index);
    }
    //查询共用方法
    function query () {
        var table = layui.table;
        table.reload('idTest', {
            where: {content: $("#content").val(),fk_resource_id: $('#fk_resource_id').val()}
        });
    }
</script>
</body>
</html>